package xyz.zhouzhaodong.transactional.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.zhouzhaodong.transactional.service.IUserService;

import javax.annotation.Resource;

/**
 * 测试
 *
 * @author zhouzhaodong
 */
@RestController
@RequestMapping("/transactional")
public class TransactionalTestController {

    @Resource
    IUserService userService;

    /**
     * 事务方法内部捕捉了异常，且没有抛出新的异常
     */
    @GetMapping("/three")
    public void threeTest(){
        try {
            userService.threeTest();
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * @Transactional注解标注方法修饰符为非public
     */
    @GetMapping("/two")
    public void twoTest(){
        try {
            userService.twoTest();
        } catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     * 在类内部调用调用类内部@Transactional标注的方法
     */
    @GetMapping("/one")
    public void oneTest(){
        try {
            userService.oneTest();
        } catch (Exception e){
            e.printStackTrace();
        }
    }

}
